package com.kungkhies.mvc.feeds.view;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.view.feed.AbstractRssFeedView;

import com.kungkhies.domain.kungkhie.KungkhieSummary;
import com.sun.syndication.feed.rss.Item;

public class KungkhiesRssView extends AbstractRssFeedView
{
    @Override
    protected List<Item> buildFeedItems(
            Map<String, Object> model,
            HttpServletRequest request,
            HttpServletResponse response) throws Exception
    {

        @SuppressWarnings("unchecked")
        List<KungkhieSummary> kungkhies = (List<KungkhieSummary>) model.get("kungkhies");
        List<Item> items = new ArrayList<Item>();
        for (KungkhieSummary kungkhie : kungkhies)
        {
            Item item = new Item();
            item.setTitle(kungkhie.getText());
            item.setPubDate(kungkhie.getWhen());
            item.setAuthor(kungkhie.getKungkher().getFullName());
            items.add(item);
        }

        return items;
    }
}
